/*--------------------------------------------------------------------------------------------------
Yatak Operation System Project Copyright 2012-2013
Author : Ilya Churaev
Started : 8 Jan 2013		Updated : 12 Jan 2013
File Name : pm.h			Purpose : Power manager header, acpi control
--------------------------------------------------------------------------------------------------*/
#ifndef _POWER_MANAGER_H
#define _POWER_MANAGER_H

#ifdef __cplusplus
extern "C" {
#endif

#include <types.h>

struct RSDPtr
{
	byte Signature[8];
	byte CheckSum;
	byte OemID[6];
	byte Revision;
	dword *RsdtAddress;
};

struct FACP
{
	byte Signature[4];
	dword Length;
	byte unneded1[40 - 8];
	dword *DSDT;
	byte unneded2[48 - 44];
	dword *SMI_CMD;
	byte ACPI_ENABLE;
	byte ACPI_DISABLE;
	byte unneded3[64 - 54];
	dword *PM1a_CNT_BLK;
	dword *PM1b_CNT_BLK;
	byte unneded4[89 - 72];
	byte PM1_CNT_LEN;
};

// check if the given address has a valid header
unsigned int *acpiCheckRSDPtr(unsigned int *ptr);
// finds the acpi header and returns the address of the rsdt
unsigned int *acpiGetRSDPtr(void);
// checks for a given header and validates checksum
int acpiCheckHeader(unsigned int *ptr, char *sig);

int acpiEnable(void);
// Init Acpi
int init_acpi(void);
// Acpi power off
void acpiPowerOff(void);
// reboot
void __reboot ();

/* keyboard interface IO port: data and control
   READ:   status port
   WRITE:  control register */
#define KBRD_INTRFC 0x64
 
/* keyboard interface bits */
#define KBRD_BIT_KDATA 0 /* keyboard data is in buffer (output buffer is empty) (bit 0) */
#define KBRD_BIT_UDATA 1 /* user data is in buffer (command buffer is empty) (bit 1) */
 
#define KBRD_IO 0x60 /* keyboard IO port */
#define KBRD_RESET 0xFE /* reset CPU command */

#ifdef __cplusplus
}
#endif

#endif
